//
//  AppDelegate.h
//  KG
//
//  Created by Eugene Braginets on 14.03.12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <CommonCrypto/CommonDigest.h>
#import <CommonCrypto/CommonHMAC.h>
#import <CommonCrypto/CommonCryptor.h>
#import "JSONKit.h"
#import "FBConnect.h"
#import "FBDialog.h"
#import "FBRequest.h"



#define kPlayerItem (NSString*) @"PlayItem"
#define kNewsItem (NSString*) @"NewsItem"
#define kPitchItem (NSString*) @"PtchItem"
#define kMessageItem (NSString*) @"MesgItem"
#define kBannerItem (NSString*) @"BannItem"
#define kEventItem (NSString*) @"EvntItem"
#define kCompItem (NSString*) @"CompItem"
#define kGameItem (NSString*) @"GameItem"
#define kChangeItem (NSString*) @"ChngItem"



//Fixtures and results constants
#define kAllCompetitions (NSString*) @"All competitions"

#define kFootResults (NSString*) @"Football Results"
#define kFootFixtures (NSString*) @"Football Fixtures"
#define kHurlResults (NSString*) @"Hurling Results"
#define kHurlFixtures (NSString*) @"Hurling Fixtures"

#define kCompPanel [NSArray arrayWithObjects:@"7 days",@"Kerry",@"Munster",@"National", nil]
#define kCompLevels [NSArray arrayWithObjects:@"Senior",@"Intermediate",@"Junior",@"Minor", nil]

#define kDataArrayStore (NSMutableDictionary*) [myAppDelegate dataArraysStore]
#define kNewsArray (NSMutableArray*) [[myAppDelegate dataArraysStore] objectForKey:kNewsItem]
#define kPlayersArray (NSMutableArray*) [[myAppDelegate dataArraysStore] objectForKey:kPlayerItem]
#define kPitchesArray (NSMutableArray*) [[myAppDelegate dataArraysStore] objectForKey:kPitchItem]
#define kBannersArray (NSMutableArray*) [[myAppDelegate dataArraysStore] objectForKey:kBannerItem]
#define kMessagesArray (NSMutableArray*) [[myAppDelegate dataArraysStore] objectForKey:kMessageItem]
#define kEventsArray (NSMutableArray*) [[myAppDelegate dataArraysStore] objectForKey:kEventItem]
#define kCompsArray (NSMutableArray*) [[myAppDelegate dataArraysStore] objectForKey:kCompItem]

//#define kFootResultsDict (NSMutableDictionary*) [[myAppDelegate fixturesAndResults] objectForKey:kFootResultsItem]
//#define kFootFixturesDict (NSArray*) [[myAppDelegate fixturesAndResults] objectForKey:kFootFixturesItem]
//#define kHurlResultsDict (NSMutableDictionary*) [[myAppDelegate fixturesAndResults] objectForKey:kHurlResultsItem]
//#define kHurlFixturesDict (NSMutableDictionary*) [[myAppDelegate fixturesAndResults] objectForKey:kHurlFixturesItem]

#define kGetMatchesURL (NSString*) @"https://kerrygaa.ie/a_get_items.php?type=91&"
#define kGetCompsURL (NSString*) @"https://kerrygaa.ie/a_get_items.php?type=90&"

//array of links for each panel (7days, Kerry, Munster, National)
#define kReqArrayFootballFixtures [NSArray arrayWithObjects:@"https://kerrygaa.ie/a_get_items.php?type=91&panel=1&daysAfter=7&fixturesOnly=y&compStyle=football&",@"https://kerrygaa.ie/a_get_items.php?type=91&panel=2&includeCountyGames=N&includeProvincialGames=N&includeClubGames=Y&includeCollegeGames=Y&includeSchoolGames=Y&fixturesOnly=y&compStyle=football&",@"https://kerrygaa.ie/a_get_items.php?type=91&panel=3&provinceName=Munster&includeCountyGames=Y&includeProvincialGames=Y&includeClubGames=N&includeCollegeGames=N&includeSchoolGames=N&fixturesOnly=y&compStyle=football&",@"https://kerrygaa.ie/a_get_items.php?type=91&panel=4&countyBoardID=13&includeProvincialGames=N&includeClubGames=N&includeCollegeGames=N&includeSchoolGames=N&fixturesOnly=y&compStyle=football&", nil]

#define kReqArrayFootballResults [NSArray arrayWithObjects:@"https://kerrygaa.ie/a_get_items.php?type=91&panel=1&daysPrevious=7&reverseDateOrder=Y&resultsOnly=y&compStyle=football&",@"https://kerrygaa.ie/a_get_items.php?type=91&panel=2&includeCountyGames=N&includeProvincialGames=N&includeClubGames=Y&includeCollegeGames=Y&includeSchoolGames=Y&reverseDateOrder=Y&resultsOnly=y&compStyle=football&",@"https://kerrygaa.ie/a_get_items.php?type=91&panel=3&provinceName=Munster&includeCountyGames=Y&includeProvincialGames=Y&includeClubGames=N&includeCollegeGames=N&includeSchoolGames=N&reverseDateOrder=Y&resultsOnly=y&compStyle=football&",@"https://kerrygaa.ie/a_get_items.php?type=91&panel=4&countyBoardID=13&includeProvincialGames=N&includeClubGames=N&includeCollegeGames=N&includeSchoolGames=N&reverseDateOrder=Y&resultsOnly=y&compStyle=football&", nil]

#define kReqArrayHurlingFixtures [NSArray arrayWithObjects:@"https://kerrygaa.ie/a_get_items.php?type=91&panel=1&countyBoardID=13&daysAfter=7&fixturesOnly=y&compStyle=hurling&",@"https://kerrygaa.ie/a_get_items.php?type=91&panel=2&countyBoardID=13&includeCountyGames=N&includeProvincialGames=N&includeClubGames=Y&includeCollegeGames=Y&includeSchoolGames=Y&fixturesOnly=y&compStyle=hurling&",@"https://kerrygaa.ie/a_get_items.php?type=91&panel=3&provinceName=Munster&includeCountyGames=Y&includeProvincialGames=Y&includeClubGames=Y&includeCollegeGames=N&includeSchoolGames=N&fixturesOnly=y&compStyle=hurling&",@"https://kerrygaa.ie/a_get_items.php?type=91&panel=4&countyBoardID=13&includeProvincialGames=N&includeClubGames=N&includeCollegeGames=N&includeSchoolGames=N&fixturesOnly=y&compStyle=hurling&", nil]

#define kReqArrayHurlingResults [NSArray arrayWithObjects:@"https://kerrygaa.ie/a_get_items.php?type=91&panel=1&countyBoardID=13&daysPrevious=7&reverseDateOrder=Y&resultsOnly=Y&compStyle=hurling&",@"https://kerrygaa.ie/a_get_items.php?type=91&panel=2&countyBoardID=13&includeCountyGames=N&includeProvincialGames=N&includeClubGames=Y&includeCollegeGames=Y&includeSchoolGames=Y&reverseDateOrder=Y&resultsOnly=Y&compStyle=hurling&",@"https://kerrygaa.ie/a_get_items.php?type=91&panel=3&provinceName=Munster&includeCountyGames=Y&includeProvincialGames=Y&includeClubGames=Y&includeCollegeGames=N&includeSchoolGames=N&reverseDateOrder=Y&resultsOnly=Y&compStyle=hurling&",@"https://kerrygaa.ie/a_get_items.php?type=91&panel=4&countyBoardID=13&includeProvincialGames=N&includeClubGames=N&includeCollegeGames=N&includeSchoolGames=N&reverseDateOrder=Y&resultsOnly=Y&compStyle=hurling&", nil]


#define kGetEventURL (NSString*) @"https://kerrygaa.ie/a_get_items.php?type=11"
#define kGetNewsURL (NSString*) @"https://kerrygaa.ie/a_get_items.php?type=1"
#define kGetMessageURL (NSString*) @"https://kerrygaa.ie/a_get_items.php?type=9"
#define kGetBannerURL (NSString*) @"https://kerrygaa.ie/a_get_items.php?type=10"
#define kGetPlayersURL (NSString*) @"https://kerrygaa.ie/a_get_items.php?type=7"
#define kGetPitchesURL (NSString*) @"https://kerrygaa.ie/a_get_items.php?type=5"
#define kGetChangesURL (NSString*) @"https://kerrygaa.ie/a_get_items.php?type=0"

//#define kGetPitchesURL (NSString*) @"http://192.168.0.101/get_item_msg.php"


#define myAppDelegate (AppDelegate*)[[UIApplication sharedApplication] delegate]


@class DataItem;
@class StartScreenViewController;
@interface AppDelegate : UIResponder <FBRequestDelegate, FBSessionDelegate, FBDialogDelegate, UIApplicationDelegate> {
}

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) StartScreenViewController *ss;

//data to refresh
@property (strong, nonatomic) NSMutableDictionary* timeStamps;
@property (strong, nonatomic) NSMutableDictionary* refreshData;

//error counter
@property (assign, nonatomic) int errors;

//DATA stores
@property (strong, nonatomic) NSString* serversAnswer;
@property (strong, nonatomic) NSMutableDictionary *serversRespondsStore;
@property (strong,nonatomic) NSMutableDictionary *dataArraysStore;

@property (strong, nonatomic) NSMutableDictionary* fixturesAndResults;


//these properties defines how many items from players/news should be preloaded at start
@property (assign, nonatomic) int loadNews;
@property (assign, nonatomic) int loadPlayers;

//these properties counts banners and messages to avoid its reset on page change
@property (assign, nonatomic) int countBanner;
@property (assign, nonatomic) int countMessage;
@property (assign, nonatomic) int order; //0-msg, 1 - banner


//timer for banners
@property (strong, nonatomic) NSTimer* timer;
@property (strong, nonatomic) NSDate *timeStamp;

//timer for datarefresh
@property (strong, nonatomic) NSTimer* timerDataRefresh;

//property for FB delegate
@property (strong, nonatomic) Facebook *facebook;



//server interaction methods
- (void) getData:(NSString*)request andType:(NSString*)type;
- (void) gotData:(NSNotification *)notify;
- (void)loadImage:(DataItem*)item;
- (void) sendRequest:(NSString*)request;

//FB
- (void) startFB;

//Navigation skeleton cration
- (void) createNavigation;

//Utilities
- (BOOL ) stringIsEmpty:(NSString *) aString;
- (NSData *)doSha1:(NSData *)dataIn;
- (NSString *) decodeFromURLString: (NSString*) input;
- (NSString *) encodeToURLString: (NSString*) input;    
- (void)msg: (NSString*) text;
- (UIImage *)scale:(UIImage *)image toSize:(CGSize)size;
- (NSString*) timeStampToString:(int) timeStamp;
- (NSString*) timeStampToStringOnlyDate:(int) timeStamp;
- (UIImageView*) roundCorners:(UIImageView*)image frameSize:(CGSize)size radius:(float)radius frameBorderThickness:(float) thickness;

@end
